class LibrarianController < ApplicationController
  before_filter :librarian_authorize
  def index
  end
  
  def new
  end
  
  def edit
    @borrowing = Borrowing.find(params[:id])
  end
  def list_borrowing
    #@borrowing = Borrowing.find(:all, :conditions => { :user_id => params[:user_id] })
    @borrowings = Borrowing.find_all_by_user_id(params[:user_id])
    respond_to do |format|
      format.html # list_borrowing.html.erb
      format.json { render json: @borrowings }
    end
    
  end
  
  def update
    @borrowing = Borrowing.find(params[:id])
    if @borrowing
      @borrowing.return_date = Date.current
      @borrowing.save
      @document = Document.find_by_isbn(@borrowing.document_id)
      @document.current_number += 1;
      @document.save
      respond_to do |format|
          format.html { redirect_to librarian_url, notice: 'Returning was successfully' }
      end
    else
      respond_to do |format|
          format.html { redirect_to librarian_url, notice: 'Fail' }
      end
    end
 
  end
  
  
  
end
